#include "stdafx.h"
#include "Selection.h"

bool Selection::IsSelection()
{
	return SelStart != SelEnd;
}

void Selection::ClearSelection()
{
	SelStart.col = SelStart.row = 0;
	SelEnd.col = SelEnd.row = 0;
	SelFirst.col = SelFirst.row = 0;
	SelSecond.col = SelSecond.row = 0;
}

bool Selection::IsPtInSelection(int row, int col)
{
	NormalizeSelection();

	DocPoint pt(row, col);
	if(pt >= SelFirst && pt < SelSecond) return true;
	return false;
}

#define max(a,b)            (((a) > (b)) ? (a) : (b))
#define min(a,b)            (((a) < (b)) ? (a) : (b))

void Selection::NormalizeSelection()
{
	SelFirst = min(SelStart, SelEnd);
	SelSecond = max(SelStart, SelEnd);
}

void Selection::SetSelStart(int row, int col)
{
	SelStart.row = row;
	SelStart.col = col;
}

void Selection::SetSelEnd(int row, int col)
{
	SelEnd.row = row;
	SelEnd.col = col;
}

DocPoint Selection::GetSelStart()
{
	return SelStart;
}

DocPoint Selection::GetSelEnd()
{
	return SelEnd;
}

DocPoint Selection::GetSelFirst()
{
	return SelFirst;
}

DocPoint Selection::GetSelSecond()
{
	return SelSecond;
}


Selection::Selection(void)
{
}

Selection::~Selection(void)
{
}

